var WzAdvInfoDlg = {
    advId:'',
    type:'',
    rewardType:'',
    couponIds: '',
    quAdvId: '',
    quAdvAskId: '',
    details:'',
    screenGender:'',
    wzAdvInfoData : {}
};

/**
 * 关闭此对话框
 */
WzAdvInfoDlg.close = function() {
    parent.layer.close(window.parent.WzAdv.layerIndex);
}


$(document).ready(function () {
    var isEnd=false;
    $("#wizard").steps();
    $("#form").steps({
        bodyTag: "fieldset",
        onStepChanging: function (event, currentIndex, newIndex) {
            // Always allow going backward even if the current step contains invalid fields!
            if (currentIndex > newIndex) {
                return true;
            }
            var form = $(this);

            // Clean up if user went backward before
            if (currentIndex < newIndex) {
                // To remove error styles
                $(".body:eq(" + newIndex + ") label.error", form).remove();
                $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
            }

            if (currentIndex === 0) {
                var type=$("#type").val();
                var rewardType=$("#rewardType").val();
                var advId=$("#advId").val();
                WzAdvInfoDlg.type=type;
                WzAdvInfoDlg.rewardType=rewardType;
                WzAdvInfoDlg.advId=advId;
                var ajax = new $ax(Feng.ctxPath + "/wzAdv/getInfo", function (data) {
                }, function (data) {
                });
                ajax.set("type", WzAdvInfoDlg.type);
                ajax.set("rewardType", WzAdvInfoDlg.rewardType);
                ajax.set("advId", WzAdvInfoDlg.advId);
                ajax.start()
            }
            if (currentIndex === 1) {
                var selected = $('#WzPicFileTable').bootstrapTable('getSelections');
                if (selected[0] != null) {

                    var picUrl=selected[0]['fileUrl'].substring(26);
                    // console.log(picUrl);
                    WzAdvInfoDlg.picUrl = picUrl;
                    var ajax = new $ax(Feng.ctxPath + "/wzAdv/getInfo", function (data) {
                    }, function (data) {
                    });
                    ajax.set("picUrl", WzAdvInfoDlg.picUrl);
                    ajax.start();
                }
            }
            if (currentIndex === 2) {
                var details=$("#details").val();
                WzAdvInfoDlg.details=details;
                var ajax = new $ax(Feng.ctxPath + "/wzAdv/getInfo", function (data) {
                }, function (data) {
                });
                ajax.set("details", WzAdvInfoDlg.details);
                ajax.start()

            }
            if (currentIndex === 3) {
                var screenGender=$("#screenGender").val();
                WzAdvInfoDlg.screenGender=screenGender;
                var ajax = new $ax(Feng.ctxPath + "/wzAdv/getInfo", function (data) {
                }, function (data) {
                });
                ajax.set("screenGender", WzAdvInfoDlg.screenGender);
                ajax.start()

            }
            // Disable validation on fields that are disabled or hidden.
            form.validate().settings.ignore = ":disabled,:hidden";

            // Start validation; Prevent going forward if false
            return form.valid();
        },
        onStepChanged: function (event, currentIndex, priorIndex) {
            // Suppress (skip) "Warning" step if the user is old enough.
            // if (currentIndex === 2 && Number($("#age").val()) >= 18) {
            //     $(this).steps("next");
            // }
            // Suppress (skip) "Warning" step if the user is old enough and wants to the previous step.
            //if (currentIndex === 2 && priorIndex === 3) {
            //    $(this).steps("previous");
            //}
        },
        onFinishing: function (event, currentIndex) {

            var form = $(this);
            // Disable validation on fields that are disabled.
            // At this point it's recommended to do an overall check (mean ignoring only disabled fields)
            form.validate().settings.ignore = ":disabled";
            // Start validation; Prevent form submission if false
            return form.valid();

        },
        onFinished: function (event, currentIndex) {
            if(currentIndex===3)(
              isEnd=true
            )
            if(isEnd){
                var form = $(this);
                // Submit form input
                form.submit();
                Feng.success("修改成功，请刷新表格")
                // window.parent.WzAdv.table.refresh();
                WzAdvInfoDlg.close();
            }else{
                Feng.info("请点击下一步")
            }
        },
        onCanceled: function () {
            parent.layer.close(window.parent.WzAdv.layerIndex);
        }
    }).validate({
        errorPlacement: function (error, element) {
            element.before(error);
        },
        rules: {
            confirm: {
                equalTo: "#password"
            }
        }
    });

    $('.summernote').summernote({
        lang: 'zh-CN'
    });
});

// var saveAdvDetail = function () {
//     $("#eg").removeClass("no-padding");
//     var aHTML = $('.click2edit').code();//save HTML If you need(aHTML: array).
//     console.log(aHTML);
//     $('.click2edit').destroy();
// };